package com.example.administrator.fagementwc;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

public class ChatFragment extends Fragment implements ContactAdapter.OnItemClickLitener{

    private List<Contact> contactList;

    public ChatFragment() {
        // Required empty public constructor
        contactList = new ArrayList<>();
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View mview = inflater.inflate(R.layout.chat_layout, container, false);

        initContact();

        RecyclerView recyclerView = (RecyclerView) mview.findViewById(R.id.contact_view);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);

        ContactAdapter adapter = new ContactAdapter(contactList);
        adapter.setOnItemClickLitener(this);
        recyclerView.setAdapter(adapter);

        return mview;
    }

    @Override
    public void onItemClick(int imageId, String name) {
        ChatActivity.actionStart(getActivity(), imageId, name);
    }

    public void initContact() {
        Contact contact = new Contact("zwh", R.drawable.head);
        Contact contact2 = new Contact("zwh2", R.drawable.head2);
        Contact contact3 = new Contact("zwh3", R.drawable.head3);
        contactList.add(contact);
        contactList.add(contact2);
        contactList.add(contact3);
    }
}
